/*
 * Copyright (C) 2020 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.tlgen.adapter;

import android.content.Intent;

import androidx.annotation.NonNull;

import com.tlgen.R;
import com.tlgen.activity.CreditActivity;
import com.tlgen.activity.FileActivity;
import com.tlgen.activity.FingerPrintActivity;
import com.tlgen.activity.PayOrderActivity;
import com.tlgen.activity.ProfileActivity;
import com.tlgen.activity.ProgressActivity;
import com.tlgen.activity.RebackCodeActivity;
import com.xuexiang.xui.adapter.recyclerview.BaseRecyclerAdapter;
import com.xuexiang.xui.adapter.recyclerview.RecyclerViewHolder;
import com.xuexiang.xui.adapter.simple.AdapterItem;
import com.xuexiang.xui.widget.imageview.ImageLoader;
import com.xuexiang.xui.widget.imageview.RadiusImageView;

/**
 * 普通九宫格
 *
 * @author xuexiang
 * @since 2020/3/11 8:33 PM
 */
public class CommonGridAdapter extends BaseRecyclerAdapter<AdapterItem> {

    private boolean mIsCircle;

    public CommonGridAdapter(boolean isCircle) {
        super();
        mIsCircle = isCircle;
    }


    @Override
    protected int getItemLayoutId(int viewType) {
        return R.layout.adapter_common_grid_item;
    }

    @Override
    protected void bindData(@NonNull RecyclerViewHolder holder, int position, AdapterItem item) {
        if (item != null) {
            RadiusImageView imageView = holder.findViewById(R.id.riv_item);
            imageView.setCircle(mIsCircle);
            ImageLoader.get().loadImage(imageView, item.getIcon());

            holder.text(R.id.tv_title, item.getTitle().toString().substring(0, 1));
            holder.text(R.id.tv_sub_title, item.getTitle());

            // 设置监听
            holder.click(R.id.ll_container, v -> {
                if ("贷款".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    // adapter中启动activity
                    holder.getContext().startActivity(new Intent(holder.getContext(), CreditActivity.class));
                  //  getActivity().startActivity(new Intent(getContext(), CreditActivity.class));
                }
                if ("指纹".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), FingerPrintActivity.class));
                 //   getActivity().startActivity(new Intent(getContext(), FingerPrintActivity.class));
                }
                if ("文件".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), FileActivity.class));
                  //  getActivity().startActivity(new Intent(getContext(), FileActivity.class));
                }
                if ("订单".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), PayOrderActivity.class));
                  //  getActivity().startActivity(new Intent(getContext(), PayOrderActivity.class));
                }
                if ("进度".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), ProgressActivity.class));
                  //  getActivity().startActivity(new Intent(getContext(), ProgressActivity.class));
                }
                if ("校验码".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), RebackCodeActivity.class));
                 //   getActivity().startActivity(new Intent(getContext(), RebackCodeActivity.class));
                }
                if ("我的".equals(item.getTitle())) {
                    System.out.println("点击的项为: " + item.getTitle());
                    holder.getContext().startActivity(new Intent(holder.getContext(), ProfileActivity.class));
                 //   getActivity().startActivity(new Intent(getContext(), ProfileActivity.class));
                }
            });

        }
    }

}
